var a = getApp();

Page({
    data: {
        avatar: "",
        name: "",
        role: "",
        vipList: [],
        vipDate: "",
        priceList: [],
        inviteDesc: "",
        shareData: {}
    },
    loadData: function() {
        var t = this;
        a.network.post({
            url: a.url.vipUserInfo,
            params: {},
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(e) {
                if (1 == e.data.result) {
                    var n, i = e.data.data.vipDate;
                    n = 0 == i.length ? "未购买VIP会员" : t.isVip(i) ? "会员有效期至" + i : "您的VIP会员已到期", t.setData({
                        avatar: e.data.data.avatar,
                        name: e.data.data.name,
                        role: e.data.data.role,
                        vipList: e.data.data.vipList,
                        vipDate: i,
                        priceList: e.data.data.priceList,
                        state: n,
                        inviteDesc: e.data.data.inviteDesc
                    });
                } else a.util.showToast(e.data.message);
            },
            fail: function() {
                a.util.showToast("获取VIP信息失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading();
            }
        });
    },
    loadShareData: function() {
        var t = this;
        a.network.post({
            url: a.url.getInviteRegisterInfo,
            params: {},
            before: function() {},
            success: function(a) {
                1 == a.data.result && t.setData({
                    shareData: a.data.data
                });
            },
            fail: function() {},
            complete: function() {}
        });
    },
    generateOrder: function(t) {
        var e = this;
        a.network.post({
            url: a.url.generateWeiXinProgramVipOrder,
            params: {
                type: t,
                openId: wx.getStorageSync(a.storage.openid)
            },
            before: function() {
                wx.showNavigationBarLoading();
            },
            success: function(t) {
                if (1 == t.data.result) {
                    var n = t.data.data.package, i = t.data.data.timeStamp, o = t.data.data.nonceStr, s = t.data.data.paySign;
                    wx.requestPayment({
                        timeStamp: i + "",
                        nonceStr: o,
                        package: n,
                        signType: "MD5",
                        paySign: s,
                        success: function(t) {
                            a.util.showToast("支付成功"), e.loadData();
                        },
                        fail: function(t) {
                            a.util.showToast(t.err_desc), console.log("支付失败：" + t.message + t.detail + t.errMsg);
                        }
                    });
                } else a.util.showToast(t.data.message);
            },
            fail: function() {
                a.util.showToast("获取支付信息失败");
            },
            complete: function() {
                wx.hideNavigationBarLoading();
            }
        });
    },
    isVip: function(a) {
        console.log(a);
        var t = new Date(a), e = new Date();
        return console.log("endDate:" + t), console.log("nowDate:" + e), console.log(t > e), 
        t > e;
    },
    clickBuy: function(a) {
        var t = a.currentTarget.dataset.index;
        this.generateOrder(t);
    },
    onLoad: function(a) {
        this.loadData(), this.loadShareData();
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {
        return {
            title: this.data.shareData.title,
            path: this.data.shareData.path,
            imageUrl: this.data.shareData.image,
            success: function(a) {},
            fail: function(a) {}
        };
    }
});